<?php
include 'config.php';
include 'functions.php';
function clean($text) {
	$text = strip_tags($text);
	$text = trim($text);
	return ($text);
	//output clean text
};

$lextitle = mysqli_real_escape_string($con, clean($_POST['tb_lexTitle']));
$_SESSION['lextitle'] = $lextitle;

//$lexcontext = $_POST['context'];
$lexcreated = date("Y-m-d H:i:s");

$_SESSION['lexcreated'] = $lexcreated;

$userid = $_SESSION['userid'];

$query = "INSERT INTO lexsettings (userid, lextitle, lexcreated) VALUES ('$userid','$lextitle','$lexcreated')";
echo $query;
$result = mysqli_query($con, $query) or die("Could not record lex in database");


$getLexid = getLexid($lexcreated);
$_SESSION['lexid']= $getLexid; 
$lexid = $_SESSION['lexid'];

/*
//contexts
$lexcontext = $_POST['cb_context'];
	$contexts = implode(",", $lexcontext);
	//echo $contexts;
		$query = "INSERT INTO context_response (lexid, context) VALUES ('$lexid', '$contexts')";
		$result = mysqli_query($con, $query) or die("Could not record contexts in database");*/
		if (isset($_POST['cb_context_1']))
			{
			$context1 = $_POST['cb_context_1'];}
			else
			{
			$context1 = "" ;
			}
			if (isset($_POST['cb_context_2']))
			{
			$context2 = $_POST['cb_context_2'];}
			else
			{
			$context2 = "" ;
			}
			if (isset($_POST['cb_context_3']))
			{
			$context3 = $_POST['cb_context_3'];}
			else
			{
			$context3 = "" ;
			}
$query = "INSERT INTO context_response (lexid, context1, context2, context3) VALUES ('$lexid','$context1','$context2','$context3')";
$result = mysqli_query($con, $query) or die("Could not record context in database");
		

/*
//skills
$skill = $_POST['cb_skill'];
	$skills = implode(",", $skill);
	//echo $contexts;
		$query = "INSERT INTO skill_response (lexid, skill) VALUES ('$lexid', '$skills')";
		$result = mysqli_query($con, $query) or die("Could not record contexts in database" );*/


$skill1 = $_POST['cb_skill_1'];
$skill2 = $_POST['cb_skill_2'];
$skill3 = $_POST['cb_skill_3'];
$skill4 = $_POST['cb_skill_4'];
$skill5 = $_POST['cb_skill_5'];
$skill6 = $_POST['cb_skill_6'];
$skill7 = $_POST['cb_skill_7'];

$query = "INSERT INTO skill_response (lexid, skill1, skill2, skill3, skill4, skill5, skill6, skill7) VALUES ('$lexid','$skill1','$skill2','$skill3','$skill4','$skill5','$skill6','$skill7')";
$result = mysqli_query($con, $query) or die("Could not record skills in database");


header('LOCATION: newlex2.php');
?>